﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

// Token: 0x020003A2 RID: 930
public class DragMoveUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IEventSystemHandler
{
	// Token: 0x1700023D RID: 573
	// (get) Token: 0x0600171E RID: 5918 RVA: 0x0009B11C File Offset: 0x0009931C
	// (set) Token: 0x0600171F RID: 5919 RVA: 0x0009B124 File Offset: 0x00099324
	public bool IsDragging { get; protected set; }

	// Token: 0x06001720 RID: 5920 RVA: 0x0009B130 File Offset: 0x00099330
	private void Awake()
	{
		if (this.moveTarget == null)
		{
			this.moveTarget = base.transform;
		}
		this.myRect = base.GetComponent<RectTransform>();
		this.moveRect = (this.moveTarget as RectTransform);
	}

	// Token: 0x06001721 RID: 5921 RVA: 0x0009B16C File Offset: 0x0009936C
	private void Update()
	{
	}

	// Token: 0x06001722 RID: 5922 RVA: 0x0009B170 File Offset: 0x00099370
	public void OnBeginDrag(PointerEventData data)
	{
		this.IsDragging = true;
	}

	// Token: 0x06001723 RID: 5923 RVA: 0x0009B17C File Offset: 0x0009937C
	public void OnDrag(PointerEventData data)
	{
		Vector2 delta = data.delta;
		Vector2 vector = this.moveTarget.position;
		vector += delta;
		this.moveTarget.position = vector;
		this.CheckMoveArea();
		this.IsDragging = true;
	}

	// Token: 0x06001724 RID: 5924 RVA: 0x0009B1C8 File Offset: 0x000993C8
	public void OnEndDrag(PointerEventData data)
	{
		this.IsDragging = false;
	}

	// Token: 0x06001725 RID: 5925 RVA: 0x0009B1D4 File Offset: 0x000993D4
	private void CheckMoveArea()
	{
		Canvas componentInParent = base.transform.GetComponentInParent<Canvas>();
		float d = 1f / componentInParent.scaleFactor;
		Vector3[] array = new Vector3[4];
		this.myRect.GetWorldCorners(array);
		Vector2 vector = Vector2.zero;
		float x = array[0].x;
		float x2 = array[2].x;
		float y = array[1].y;
		float y2 = array[0].y;
		if (x < 0f)
		{
			vector += new Vector2(-x, 0f) * d;
		}
		if (x2 > (float)Screen.width)
		{
			vector += new Vector2((float)Screen.width - x2, 0f) * d;
		}
		if (y > (float)Screen.height)
		{
			vector += new Vector2(0f, (float)Screen.height - y) * d;
		}
		if (y2 < 0f)
		{
			vector += new Vector2(0f, -y2) * d;
		}
		this.moveRect.anchoredPosition += vector;
	}

	// Token: 0x04001AE0 RID: 6880
	[SerializeField]
	private Transform moveTarget;

	// Token: 0x04001AE2 RID: 6882
	private RectTransform myRect;

	// Token: 0x04001AE3 RID: 6883
	private RectTransform moveRect;
}
